package edu.bit.water.service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import edu.bit.water.dao.CleanProductDao;
import edu.bit.water.entity.CleanProduct;

@Service
public class CleanProductService {
	@Autowired
	private CleanProductDao cleanProductDao;

	public int insert(CleanProduct cleanProduct) {
		int n = cleanProductDao.insert(cleanProduct);
		return n;
	}

	public int deleteChart(List<Integer> ids) {
		try {
			for (Integer id : ids) {
				cleanProductDao.delete(id);
			}
			return 1;
		} catch (Exception e) {
			e.printStackTrace();
			return 0;
		}
	}

	public Map<String, String> updateChart(CleanProduct cleanProduct) {
		Map<String, String> modelMap = new HashMap<>();
		int n = cleanProductDao.update(cleanProduct);
		if (n == 1)
			modelMap.put("status", "success");
		else 
			modelMap.put("status", "failed");
		return modelMap;
	}

	public List<CleanProduct> select(int label_id) {
		List<CleanProduct> list = cleanProductDao.select(label_id);
		return list;
	}

}
